
package rmiexample.hello;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

/**
 *
 * @author Jadzia
 */
public class Server implements Hello{
    public Server() {}

    public String sayHello() throws RemoteException {
        return "Hello, World!";
    }

    public static void main(String args[]) {
        try {
            Server obj = new Server();
            Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);

            //bind the remote object's stub in the registry
            LocateRegistry.createRegistry(2020);
            Registry registry = LocateRegistry.getRegistry(2020);
            registry.bind("Hello", stub);

        } catch(Exception e) {
            System.err.println("Server exception: " + e.toString());
            e.printStackTrace();
        }
    }

}
